package com.elitel.frame.base.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elitel.frame.base.service.JarServerConfigService;
import com.elitel.frame.main.entity.BaseJarinfo;
import com.elitel.frame.main.entity.BaseJarmethod;
import com.elitel.frame.main.entity.BaseJarserver;
import com.elitel.frame.main.entity.CfgExtjar;
import com.elitel.frame.main.entity.ext.Census;
import com.elitel.frame.main.entity.ext.ExtCfgExtjar;


@RequestMapping("/system/jarservice")
@Controller
public class JarServerConfigController {
	
	@Resource
	private JarServerConfigService jarServerConfigServiceImpl;
	
	/**
	 * 获取左侧数据
	 * @param request
	 * @return
	 */
	@RequestMapping("/getTreeList")
	@ResponseBody
	public List<Census> getJarServerTree(HttpServletRequest request){
		List<Census> list = jarServerConfigServiceImpl.getJarServerTree();
		return list;
	}
	/**
	 * 插入jar配置
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/insertJarServer",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Object insertJarServer(@RequestBody ExtCfgExtjar cfgExtjar, HttpServletRequest request){
		String message = jarServerConfigServiceImpl.insertJarServer(cfgExtjar);
		return message;
	}
	
	/**
	 * 获取Jar集合
	 */
	@RequestMapping("/getJarList")
	@ResponseBody
	public List<BaseJarinfo> getJarList(HttpServletRequest request){
		List<BaseJarinfo> list = jarServerConfigServiceImpl.selectAllJarInfo();
		return list;
	}
	
	/**
	 * 获取包层
	 * 
	 */
	@RequestMapping("/getPackageList")
	@ResponseBody
	public List<BaseJarmethod> getPackageList(HttpServletRequest request){
		String sguid = request.getParameter("jarids");
		List<BaseJarmethod> list = jarServerConfigServiceImpl.getPackageList(sguid);
		return list;
	}
	/**
	 * 获取方法
	 * @param request
	 * @return
	 */
	@RequestMapping("/getclassmethod")
	@ResponseBody
	public List<BaseJarmethod> getclassmethod(HttpServletRequest request){
		String classname = request.getParameter("jarids");
		List<BaseJarmethod> list = jarServerConfigServiceImpl.getclassmethod(classname);
		return list;
	}
	/**
	 * 获取类
	 * @param request
	 * @return
	 */
	@RequestMapping("/getClassList")
	@ResponseBody
	public List<BaseJarmethod> getClassList(HttpServletRequest request){
		String sguid = request.getParameter("jarids");
		List<BaseJarmethod> list = jarServerConfigServiceImpl.getClassList(sguid);
		return list;
	}
	/**
	 * 删除jar配置
	 * @param request
	 * @return
	 */
	@RequestMapping("/deleteJarServer")
	@ResponseBody
	public Object deleteJarServer(HttpServletRequest request){
		String guid = request.getParameter("key");
		String message = jarServerConfigServiceImpl.deleteJarServer(guid);
		return message;
	}
	
	/**
	 * 修改jar配置
	 * @param baseJarmethod
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/updateJarServer",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Object updateJarServer(@RequestBody CfgExtjar cfgExtjar,HttpServletRequest request){
		String message = jarServerConfigServiceImpl.updateJarServer(cfgExtjar);
		return message;
	}
	
	@ResponseBody
	@RequestMapping("/selectCountGUID")
	public int selectCountGUID(HttpServletRequest request){
		String guid = request.getParameter("dbKey");
		int count = jarServerConfigServiceImpl.selectCountGUID(guid);
		return count;
	}
	
	@RequestMapping("/selectJarOne")
	@ResponseBody
	public ExtCfgExtjar selectJarOne(HttpServletRequest request){
		String guid = request.getParameter("guid");
		CfgExtjar extCfgExtjar = jarServerConfigServiceImpl.selectJarOne(guid);
		BaseJarserver baseJarserver = jarServerConfigServiceImpl.selectBaseJarServer(guid);
		ExtCfgExtjar cfgExtjar = new ExtCfgExtjar();
		cfgExtjar.setGuid(extCfgExtjar.getGuid());
		cfgExtjar.setExtjarid(extCfgExtjar.getExtjarid());
		cfgExtjar.setServicename(extCfgExtjar.getServicename());
		cfgExtjar.setCallinvoke(extCfgExtjar.getCallinvoke());
		cfgExtjar.setRemark(extCfgExtjar.getRemark());
		cfgExtjar.setExtjarclass(extCfgExtjar.getExtjarclass());
		cfgExtjar.setDbKey(extCfgExtjar.getDbKey());
		cfgExtjar.setDtSql(extCfgExtjar.getDtSql());
		cfgExtjar.setOthersql(baseJarserver.getAttach());
		return cfgExtjar;
	}
}
